$(function () {


//关注用户
$('.like-button').click(function () {
    var like=$(this).attr('like-value');
    var userid=$(this).attr('like-user');
    var that=this;
    if(like==1){//用户已经关注
        $.ajax({
            url:'/user/'+userid+'/unfan',
            type:'post',
            dataType:'json',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            success:function (data) {
                if(data.error!=0){
                    alert(data.msg);
                    return;
                }
                $(that).attr('like-value',0);
                $(that).text('关注');

            },
            error:function () {
                alert('网络开小差了...');
            }
        });
    }else{
        $.ajax({
            url:'/user/'+userid+'/fan',
            type:'post',
            dataType:'json',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            success:function (data) {
                if(data.error!=0){
                    alert(data.msg);
                    return;
                }
                $(that).attr('like-value',1);
                $(that).text('取消关注');

            },
            error:function () {
                alert('网络开小差了...');
            }
        });
    }
});
})